<template>
    <div class="LineCharts">
      <div class="lineChart" ref="lineChart" :style="{height:height,width:width}"></div>
    </div>
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  export default {
    name: 'LineCharts',
    props: {
      width: {
        type: String,
        default: '1200px'
      },
      height: {
        type: String,
        default: '340px'
      },
      listData: {
        type: Object
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.initChart()
    },
    watch: {
      listData: {
        deep: true,
        handler(val) {
          this.setOptions(val)
        }
      }
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$refs.lineChart, 'macarons')
        this.setOptions(this.listData)
      },
      setOptions(listData){
        if(listData){
          this.chart.setOption({
            title: {
              text: '收款统计'
            },
            legend: {
              data: ['下单总金额(元)', '开启通道个数(个)', '平均单笔金额(元)', '通道成功率(%)']
            },
            xAxis: {
              data: listData.time_list,
              boundaryGap: false,
              axisTick: {
                show: false
              }
            },
            tooltip: {
              trigger: 'axis',
              axisPointer: {
                type: 'cross'
              }
            },
            yAxis: {
              name: '',
              type: 'value'
            },
            series: [
              {
                name: '下单总金额(元)',
                type: 'line',
                smooth: true,
                areaStyle: {normal: {}},
                data: listData.total_list
              }, {
                name: '开启通道个数(个)',
                type: 'line',
                smooth: true,
                areaStyle: {normal: {}},
                data: listData.chaneL_count_list
              }, {
                name: '平均单笔金额(元)',
                type: 'line',
                smooth: true,
                areaStyle: {normal: {}},
                data: listData.avg_amount_list
              }, {
                name: '通道成功率(%)',
                type: 'line',
                smooth: true,
                areaStyle: {normal: {}},
                data: listData.success_rate_list
              }
            ]
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
